<template>
  <Form ref="searchForm" :model="searchForm" :rules="ruleValidate" :label-width="120">
    <Form-item prop="isPassed" :label="'是否晋级'">
      <Select v-model="searchForm.isPassed" clearable>
        <Option v-for="item in isPassedList" :value="item.key" :key="item.key">{{ item.name }}</Option>
      </Select>
    </Form-item>
  </Form>
</template>

<script>
import dataApi from '@/api/formData'
export default {
  name: 'passed',
  props: {
    row: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      ruleValidate: {
        isPassed: [{ required: true, type: 'number', message: '请选择', trigger: 'change' }]
      },
      loading: false,
      isPassedList: [
        { key: 1, name: '是' },
        { key: 0, name: '否' }
      ],
      searchForm: {
        isPassed: ''
      },
      actions: [
        {
          text: '确定',
          theme: 'primary',
          handle: () => {
            this.$refs['searchForm']
              .validate(valid => {
                if (valid) {
                  this.onClick()
                }
              })
              .catch(e => {
                this.loading = false
              })
          },
          loading: this.loading
        },
        {
          text: '取消',
          handle: () => {
            this.$emit('Close')
          }
        }
      ]
    }
  },
  mounted() {
    this.$emit('SetTitle', '晋级')
    this.$emit('SetPageWidth', 600)
    this.$emit('SetPageMinHeight', 200)
    this.$emit('SetPageActions', this.actions)
  },
  methods: {
    onClick() {
      this.loading = true
      dataApi
        .scoreIsPassed({
          parentId: this.row.id,
          isPassed: this.searchForm.isPassed
        })
        .then(res => {
          this.loading = false
          if (res.data.code == 200) {
            this.$Message.success({
              content: '操作成功',
              duration: 3
            })
            this.$emit('Close', this.row)
          }
        })
    }
  }
}
</script>
